#ifndef GAME_VIEW_H
#define GAME_VIEW_H

#include <stdio.h>
#include <stdlib.h>

#include "game_window.h"
#include "grid.h"
#include "piece.h"
#include "FTGL/ftgl.h"
#include "SDL/SDL_mixer.h"

#define SAFE_DELETE(p) {if(p) {delete(p);(p)=NULL;}}

class Game_view
{
    //Possible game states
    enum {GS_INITIALIZING, GS_RUNNING, GS_GAMEOVER, GS_WAIT};

    //Possible movements
    enum {LEFT, RIGHT, DOWN};

    public:
        Game_view();
        virtual ~Game_view();
        void Render();
        piece* current_piece;
        piece* next_piece;
        grid* mp_game_table;
        void resize(int x, int y);
        void setGameState(int state){gamestate = state;};
        void Rep_sound(int num){Mix_PlayChannel(num, sounds[num], 0);};
        void Stop_sound(int num){Mix_HaltChannel(num);};
        void Restart_game();

        int n_lines;
        int level;
        int score;


    protected:
    private:

        //privat methods
        Game_window* mgw;
        bool Background_render();
        bool Grid_render();
        void Patch_render();

        void Draw_square(float posx, float posy, int color);
        void Draw_pieces();

        void Text_render(); // Used to render score, number of lines, etc...

        //private variables

        int gamestate;

        float bw; //Board pixel width
        float bh; //Board pixel height
        FTGLPixmapFont *font; //handles the font for texts
        Mix_Chunk* sounds[10]; //Handles a sound

};

#endif // GAME_VIEW_H
